import os
import socket
import json
import datetime
from celery import Celery
from nameko.standalone.rpc import ClusterRpcProxy

from config import NamekoConfig

app = Celery('server')

# celery部分代码写在这里

@app.task
def inference(model_name,text):

    nameko_config = NamekoConfig.nameko_config
    with ClusterRpcProxy(nameko_config) as cluster_rpc:
        response = cluster_rpc.inference.inference(model_name)
        response = json.loads(response)

@app.task
def train(model_name,dataset_name):

    nameko_config = NamekoConfig.nameko_config
    with ClusterRpcProxy(nameko_config) as cluster_rpc:
        response = cluster_rpc.train.train(model_name,dataset_name)
        response = json.loads(response)